﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Forecast.Domain.Implementation
{
    public class PredictionActivityGauger : IGaugePredictionActivity
    {
        #region Variables

        private IDictionary<IPredict, int> _activityDictionary;

        #endregion
        #region Constructors

        public PredictionActivityGauger()
        {
            _activityDictionary = new Dictionary<IPredict, int>();
        }

        #endregion
        #region Interface

        public void Register(IPredict prediction)
        {
            if (_activityDictionary.ContainsKey(prediction))
                return;
            _activityDictionary.Add(prediction, 0);
            Blackboard.OfferCreated += new OfferCreatedEventHandler(Blackboard_OfferCreated);
        }

        public int GetActivityLevel(IPredict prediction)
        {
            if (_activityDictionary.ContainsKey(prediction))
                return _activityDictionary[prediction];
            return 0;
        }

        #endregion
        #region Events

        void Blackboard_OfferCreated(object sender, OfferCreatedEventArgs e)
        {
            if (_activityDictionary.ContainsKey(e.Prediction))
                _activityDictionary[e.Prediction]++;
        }

        #endregion
    }
}
